mod config;
mod server;
mod token;

use anyhow::Result;
use tracing::{info, Level};
use tokio::net::TcpListener;
use tracing_subscriber::{fmt, EnvFilter};
use tower_http::trace::TraceLayer;

#[tokio::main]
async fn main() -> Result<()> {
    
    fmt()
        .with_env_filter("tower_http=debug,info")
        .with_target(true)
        .with_thread_ids(true)
        .with_thread_names(true)
        .with_file(true)
        .with_line_number(true)
        .with_level(true)
        .init();

    let config = config::Config::load()?;
    let app = server::create_router(config.clone());

    info!("启动服务器于 {}:{}", config.host, config.port);
    let listener = TcpListener::bind(format!("{}:{}", config.host, config.port)).await?;
    axum::serve(listener, app.into_make_service()).await?;

    Ok(())
}
